var e = getApp();

Page({
    data: {
        radio: "对私账户",
        is_default: !0,
        receiverAccountNoEnc: "",
        receiverNameEnc: "",
        receiverBankChannelNo: "",
        private: !1,
        public: !1,
        type: "",
        id: "",
        show: !1,
        msg: "你确定要删除这个银行卡？"
    },
    onLoad: function(e) {
        e.type && e.id && this.setData({
            type: e.type,
            id: e.id
        });
    },
    onReady: function() {},
    onShow: function() {
        this.getShow(), "edit" == this.data.type && this.editInfo();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    addTiJiao: function() {
        var t = this;
        if (e._isTextEmpty(this.data.receiverAccountNoEnc)) wx.showToast({
            title: "请输入银行卡卡号",
            icon: "none"
        }); else {
            var a = /(^[0-9]*([0-9])?)$/;
            if (console.log(a.test(this.receiverAccountNoEnc)), a.test(this.data.receiverAccountNoEnc)) if (e._isTextEmpty(this.data.receiverNameEnc)) wx.showToast({
                title: "请输入持卡人名称",
                icon: "none"
            }); else if ("对公账户" === this.data.radio && e._isTextEmpty(this.data.receiverBankChannelNo)) wx.showToast({
                title: "请输入对公账户",
                icon: "none"
            }); else {
                var n = "";
                "对公账户" == this.data.radio ? n = 204 : "对私账户" == this.data.radio && (n = 201);
                var o = e.getNetAddresss("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.create"), i = {
                    receiverAccountNoEnc: this.data.receiverAccountNoEnc,
                    receiverAccountType: n,
                    receiverNameEnc: this.data.receiverNameEnc,
                    receiverBankChannelNo: this.data.receiverBankChannelNo,
                    default: this.data.is_default ? "1" : "0"
                };
                e._getNetWork({
                    url: o,
                    data: i,
                    success: function(e) {
                        var a = e.data;
                        1 == a.result ? (wx.showToast({
                            title: a.msg,
                            icon: "none"
                        }), t.setData({
                            receiverAccountNoEnc: "",
                            receiverNameEnc: "",
                            receiverBankChannelNo: ""
                        }), setTimeout(function() {
                            wx.navigateTo({
                                url: "/packageA/others/HJinfo/bankCardInformation/bankCardInformation"
                            });
                        }, 1e3)) : wx.showToast({
                            title: a.msg,
                            icon: "none",
                            duration: 1500
                        });
                    },
                    fail: function(e) {
                        console.log(e);
                    }
                });
            } else wx.showToast({
                title: "银行卡卡号只能为纯数字",
                icon: "none"
            });
        }
    },
    editInfo: function() {
        var t = this, a = e.getNetAddresss("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.edit"), n = {
            id: this.data.id
        };
        e._getNetWork({
            url: a,
            data: n,
            success: function(a) {
                var n = a.data;
                1 == n.result ? (console.log(n.data, "96565"), t.setData({
                    receiverAccountNoEnc: n.data.receiverAccountNoEnc,
                    receiverAccountType: n.data.receiverAccountType,
                    receiverNameEnc: n.data.receiverNameEnc,
                    receiverBankChannelNo: n.data.receiverBankChannelNo
                }), e._isTextEmpty(n.data.has_one_default) || "0" == n.data.has_one_default.default ? t.setData({
                    is_default: !1
                }) : t.setData({
                    is_default: !0
                }), "204" == t.data.receiverAccountType ? t.setData({
                    radio: "对公账户"
                }) : "201" == t.data.receiverAccountType && t.setData({
                    radio: "对私账户"
                })) : wx.showToast({
                    title: n.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    editTiJiao: function() {
        if (e._isTextEmpty(this.data.receiverAccountNoEnc)) wx.showToast({
            title: "请输入银行卡卡号",
            icon: "none"
        }); else if (e._isTextEmpty(this.data.receiverNameEnc)) wx.showToast({
            title: "请输入持卡人名称",
            icon: "none"
        }); else if ("对公账户" === this.data.radio && e._isTextEmpty(this.data.receiverBankChannelNo)) wx.showToast({
            title: "请输入对公账户",
            icon: "none"
        }); else {
            var t = "";
            "对公账户" == this.data.radio ? t = 204 : "对私账户" == this.data.radio && (t = 201);
            var a = {
                receiverAccountNoEnc: this.data.receiverAccountNoEnc,
                receiverAccountType: t,
                receiverNameEnc: this.data.receiverNameEnc,
                receiverBankChannelNo: this.data.receiverBankChannelNo,
                default: this.data.is_default ? "1" : "0",
                id: this.data.id
            }, n = e.getNetAddresss("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.edit");
            e._getNetWork({
                url: n,
                data: a,
                success: function(e) {
                    var t = e.data;
                    1 == t.result ? (wx.showToast({
                        title: t.msg,
                        icon: "none"
                    }), setTimeout(function() {
                        wx.navigateTo({
                            url: "/packageA/others/HJinfo/bankCardInformation/bankCardInformation"
                        });
                    }, 1e3)) : wx.showToast({
                        title: t.msg,
                        icon: "none",
                        duration: 1500
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        }
    },
    deleteChange: function() {
        var t = this;
        wx.showModal({
            title: "提示",
            content: "你确定要删除？",
            success: function(a) {
                if (a.confirm) {
                    t.setData({
                        show: !0
                    });
                    var n = e.getNetAddresss("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.destroy"), o = {
                        id: t.data.id
                    };
                    e._getNetWork({
                        url: n,
                        data: o,
                        success: function(e) {
                            var t = e.data;
                            1 == t.result ? (wx.showToast({
                                title: t.msg,
                                icon: "none"
                            }), wx.navigateTo({
                                url: "/packageA/others/HJinfo/bankCardInformation/bankCardInformation"
                            })) : (wx.showToast({
                                title: t.msg,
                                icon: "none",
                                duration: 1500
                            }), wx.navigateTo({
                                url: "/packageA/others/HJinfo/bankCardInformation/bankCardInformation"
                            }));
                        },
                        fail: function(e) {
                            console.log(e);
                        }
                    });
                } else a.cancel && console.log("用户点击取消");
            }
        });
    },
    getShow: function() {
        var t = this, a = e.getNetAddresss("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.create");
        e._getNetWork({
            url: a,
            success: function(e) {
                var a = e.data;
                1 == a.result ? "1" == a.data.all ? t.setData({
                    private: !0,
                    public: !0
                }) : ("1" == a.data.private && t.setData({
                    private: !0,
                    radio: "对私账户"
                }), "1" == a.data.public && t.setData({
                    public: !0,
                    radio: "对公账户"
                })) : wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    onChange: function(e) {
        this.setData({
            is_default: e.detail
        });
    },
    onChangeRadio: function(e) {
        this.setData({
            radio: e.detail
        });
    },
    onChangeOne: function(e) {
        this.setData({
            receiverAccountNoEnc: e.detail
        });
    },
    onChangeTwo: function(e) {
        this.setData({
            receiverNameEnc: e.detail
        });
    },
    onChangeThree: function(e) {
        this.setData({
            receiverBankChannelNo: e.detail
        });
    }
});